package org.phalanx.gwt.client.screens;

import org.phalanx.gwt.client.shared.MessageManager;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;

public class TopLinkPanel extends HorizontalPanel implements ClickHandler {

	private ContextPanelChooser panelChooser;
	private MessageManager msgMgr;
	
	public TopLinkPanel(ContextPanelChooser chooser, MessageManager msgMgr){
		this.panelChooser = chooser;
		this.msgMgr = msgMgr;
	}
	
	public void init(){
		this.setSpacing(10);
		addLinkButtons();
	}
	
	private void addLinkButtons(){
		Hyperlink homeLink = new Hyperlink("Home", "Home");
		Hyperlink gamesLink = new Hyperlink("Games", "Games");
		Hyperlink settingsLink = new Hyperlink("Settngs", "Settings");
		Hyperlink logOutLink = new Hyperlink("Logout", "Logout");
		
		homeLink.addClickHandler(this);
		gamesLink.addClickHandler(this);
		
		this.add(homeLink);
		this.add(gamesLink);
		this.add(settingsLink);
		this.add(logOutLink);
	}

	@Override
	public void onClick(ClickEvent event) {
		Hyperlink eventLink = (Hyperlink)event.getSource();
		
		if (eventLink.getText().equals("Home")){
			panelChooser.setContextPanel("home");
		} else if (eventLink.getText().equals("Games")){
			panelChooser.removePanelFromChooser("newgame");
			CreateGameScreen newGameScreen = new CreateGameScreen(msgMgr,panelChooser);
			newGameScreen.init();
			panelChooser.addPanelToChooser("newgame", newGameScreen);
			panelChooser.setContextPanel("newgame");
		}
	}
}
